﻿using System;
using System.Threading;
using NUnit.Framework;
using Smith.AMC;

namespace MemcachedClientTests
{
    [TestFixture]
    public class MemcachedClientTest
    {
        [Test]
        public void ClientShouldBeconfiguredAutomatically()
        {
            IMemcachedClient client = new MemcachedClient();

            ManualResetEvent evt2 = new ManualResetEvent(false);
            ICacheItem<string> item = new CacheItem<string>
            {
                CacheKey = Guid.NewGuid().ToString(),
                LifeTime = TimeSpan.FromSeconds(0),
                Value = "This is the value"
            };
      

            client.BeginAdd(
                item,
                ar =>
                {
                    ManualResetEvent evtInner = (ManualResetEvent)ar.AsyncState;
                    try
                    {
                        bool success = client.EndAdd<string>(ar);
                        if (!success)
                        {
                            Assert.Fail();
                        }
                    }
                    catch (Exception e)
                    {
                        Assert.Fail(e.ToString());
                    }
                    finally
                    {
                        evtInner.Set();
                    }
                },
                evt2);
            evt2.WaitOne();

        }

    }
}
